package com.example.java_chatroom.api;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@Component
public class TestWebSocketAPI extends TextWebSocketHandler {
    @Override
    public void afterConnectionEstablished(WebSocketSession session/*websocket连接中对应的会话*/) throws Exception {
        System.out.println("TestAPI 连接成功！");
    }

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message/*收到的消息的值*/) throws Exception {
        System.out.println("TestAPI 收到消息！");
    }

    @Override
    public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
        System.out.println("TestAPI 连接异常！");
    }

    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        System.out.println("TestAPI 连接关闭！");
    }
}
